// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLExprImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "HiveInputOutputFormat.h"
#include "../../../visitor/SQLASTVisitor.h"

// @Override
bool HiveInputOutputFormat::equals(Object_ptr o)
{
  if (this == std::dynamic_pointer_cast<HiveInputOutputFormat>(o).get())
  {
    return true;
  }
  if (o == nullptr || getClass() != o->getClass())
  {
    return false;
  }

  HiveInputOutputFormat_ptr that = std::dynamic_pointer_cast<HiveInputOutputFormat>(o);

  if (input != nullptr ? !input->equals(that->input) : that->input != nullptr)
  {
    return  false;
  }
  return output != nullptr ? output->equals(that->output) : that->output == nullptr;
}

// @Override
int HiveInputOutputFormat::hashCode()
{
  int result = input != nullptr ? input->hashCode() : 0;
  result = 31 * result + (output != nullptr ? output->hashCode() : 0);
  return result;
}

// @Override
void HiveInputOutputFormat::accept0(SQLASTVisitor_ptr v)
{
  if (v->visit(SharedObject(HiveInputOutputFormat)))
  {
    acceptChild(v, input);
    acceptChild(v, output);
  }
  v->endVisit(SharedObject(HiveInputOutputFormat));
}

// @Override
SQLObject_ptr HiveInputOutputFormat::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<HiveInputOutputFormat>(new HiveInputOutputFormat());
  std::shared_ptr<HiveInputOutputFormat> x = std::dynamic_pointer_cast<HiveInputOutputFormat>(clone_tmp);
  // HiveInputOutputFormat x = new HiveInputOutputFormat();

  if (input != nullptr)
  {
    x->setInput(std::dynamic_pointer_cast<SQLExpr>(input->clone()));
  }
  if (output != nullptr)
  {
    x->setOutput(std::dynamic_pointer_cast<SQLExpr>(output->clone()));
  }

  return x;
}

SQLExpr_ptr HiveInputOutputFormat::getInput()
{
  return input;
}

void HiveInputOutputFormat::setInput(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(HiveInputOutputFormat));
  }
  this->input = x;
}

SQLExpr_ptr HiveInputOutputFormat::getOutput()
{
  return output;
}

void HiveInputOutputFormat::setOutput(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(HiveInputOutputFormat));
  }
  this->output = x;
}
